package com.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bean.YingxiangBean;
import com.xiaochun.hxhj.R;

import java.util.List;


public class OneTypeMoreAdapter extends BaseAdapter {


    private Context context;
    private LayoutInflater mInflater;
    List<YingxiangBean.DataBean> mData;
    public int checkedPosition = 0;

    public OneTypeMoreAdapter(Context context){
        this.mInflater = LayoutInflater.from(context);
    }

    public OneTypeMoreAdapter(Context context, List<YingxiangBean.DataBean> mData){
        this.context=context;
        this.mInflater = LayoutInflater.from(context);
        this.mData=mData;


    }
    public void setData(List<YingxiangBean.DataBean> mData){
        this.mData=mData;
        checkedPosition = 0;

        notifyDataSetChanged();
    }
    public void setGone(){
        notifyDataSetChanged();
    }
    public void setCheckedItem(int position){
        this.checkedPosition=position;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int arg0) {
        return null;
    }

    @Override
    public long getItemId(int arg0) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder=new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_onetype, null);
            holder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder)convertView.getTag();
        }
        if (checkedPosition == position){
            holder.tv_name.setBackgroundResource(R.drawable.orange_re);
            holder.tv_name.setTextColor(context.getResources().getColor(R.color.colorfff));
        }else{
            holder.tv_name.setBackgroundResource(R.drawable.white_resmall);
            holder.tv_name.setTextColor(context.getResources().getColor(R.color.color666));
        }
        holder.tv_name.setText(mData.get(position).getName());

        return convertView;
    }
    public static class ViewHolder{
        TextView tv_name ;
    }



}